package com.longjianghuasheng.logistics.business.wallet

import android.annotation.SuppressLint
import android.os.Bundle
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.base.BaseTitleFragment
import com.longjianghuasheng.logistics.business.wallet.adapter.WalletAdapter
import com.longjianghuasheng.logistics.databinding.FragmentWalletBinding
import com.longjianghuasheng.logistics.entity.Wallet
import com.longjianghuasheng.logistics.ext.initLinerDecoration
import com.longjianghuasheng.logistics.ext.observer
import me.hgj.jetpackmvvm.ext.view.visible

class WalletFragment : BaseTitleFragment<WalletViewModel, FragmentWalletBinding>() {
    private val walletAdapter by lazy {
        WalletAdapter()
    }

    override fun layoutId(): Int = R.layout.fragment_wallet

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        initTitleBar("钱包")
        mDatabind.run {
            rvWallet.initLinerDecoration(adapter = walletAdapter)

        }
        walletAdapter.setOnItemClickListener { adapter, view, position ->
            navigate(R.id.walletPerMonthFragment)
        }
    }

    @SuppressLint("SetTextI18n")
    override fun createObserver() {
        super.createObserver()
        mViewModel.result.observer(this) {

            mDatabind.setData(it.data)


        }
    }

    @SuppressLint("SetTextI18n")
    private fun FragmentWalletBinding.setData(it: Wallet?) {
        it?.run {
            tvMoney.text = "￥${wallet}"
            stvAccumulative.setCenterTopString(leiji.toString())
            stvToday.setCenterTopString(jin.toString())
            stvCurrentMonth.setCenterTopString(yue.toString())
            stvTotal.setCenterTopString(zong.toString())
            clBg.visible()

            tvToWithdraw.setOnClickListener {
                navigate(R.id.withdrawFragment, Bundle().apply {
                    putString("wallet", wallet)
                    putString("zong", zong.toString())
                })
            }

            walletAdapter.setNewInstance(lists)
        }


    }

    override fun initData() {
        super.initData()
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
        mViewModel.my_wallet()
    }
}